package com.white.hot.utils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;


public class FileUtils
{
	public static void writeToFile(InputStream is, String path)
	{
		FileOutputStream fos = null;
		if(is != null && (!TextUtils.isEmpty(path)))
		{
			try
			{
				byte[] buffer = new byte[1024];
				int size;
				fos = new FileOutputStream(new File(path));
				while((size = is.read(buffer)) > 0)
				{
					fos.write(buffer, 0, size);
				}
				fos.flush();
			} catch (IOException e)
			{
				e.printStackTrace();
			}finally
			{
				if(fos != null)
				{
					try
					{
						fos.close();
					} catch (IOException e)
					{
						e.printStackTrace();
					}
				}
				if(is != null)
				{
					try
					{
						is.close();
					} catch (IOException e)
					{
						e.printStackTrace();
					}					
				}
			}
		}
	}
	
	public static String getFileSuffix(String absName)
	{
		if(TextUtils.isEmpty(absName))
			return "";
		int dotIndex = absName.indexOf('.');
		if(dotIndex > 0)
		{
			return absName.substring(dotIndex, absName.length());
		}
		return "";
	}
}
